package reducer;

import java.io.IOException;

import mapper.MaxTemperatureMapper;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

public class MaxTemperatureReducer extends Reducer<Text, IntWritable, Text, IntWritable>{

	private final static Log log = LogFactory.getLog(MaxTemperatureMapper.class);
	
	@Override
	protected void reduce(Text key, Iterable<IntWritable> values, Context context)	throws IOException, InterruptedException {
		
		//模拟操作
		Thread.sleep(100);
		
		int maxValue = Integer.MIN_VALUE;
		for(IntWritable value : values){
			
			int v = value.get();
			log.info(String.format("reducer,key:%s,value:%d \n", key.toString(), v));
			maxValue = Math.max(maxValue, v);
		}
		context.write(key, new IntWritable(maxValue));
	}
}
